package com.gooluke.redismap.controller;

import com.gooluke.redismap.config.StringRedisMapManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gooluke
 * description
 * datetime 2025-09-14 17:42
 */
@RestController
@RequestMapping("/redis")
public class RedisMapController {

    @Autowired
    private StringRedisMapManager stringRedisMapManager;

    @RequestMapping("/get")
    public String get(@RequestParam("key") String key) {
        return stringRedisMapManager.get(key);
    }

    @RequestMapping("/set")
    public boolean set(@RequestParam("key") String key, @RequestParam("value") String value) {
        return stringRedisMapManager.set(key, value);
    }

    @RequestMapping("/setExpire")
    public boolean set(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam("expire") long expire) {
        return stringRedisMapManager.set(key, value, expire);
    }

    @RequestMapping("/setNx")
    public boolean setNx(@RequestParam("key") String key, @RequestParam("value") String value) {
        return stringRedisMapManager.setNx(key, value);
    }

    @RequestMapping("/setNxExpire")
    public boolean setNx(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam("expire") long expire) {
        return stringRedisMapManager.setNx(key, value, expire);
    }

    @RequestMapping("/del")
    public boolean del(@RequestParam("key") String key) {
        return stringRedisMapManager.del(key);
    }

    @RequestMapping("/ttl")
    public long ttl(@RequestParam("key") String key) {
        return stringRedisMapManager.ttl(key);
    }

}
